//
//  PKMContributionListController.swift
//  Panku
//
//  Created by mac on 2017/2/13.
//  Copyright © 2017年 Monster. All rights reserved.
//

import UIKit
import YYKit
import SnapKit

private let PKMContributionListControllerCellID = "PKMContributionListControllerCellID"

class PKMContributionListController: PKBaseViewController ,UITableViewDataSource,UITableViewDelegate{

    //MARK: - properties
    //UI
    lazy var tableView = PKBaseTableView { (make) in
        
    }
    lazy var dailyButton = PKBaseButton.createButton()
    lazy var totalButton = PKBaseButton.createButton()
    
    
    //MARK: - life circle
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    //MARK: - UI
    override func setupRootView() {
        view.backgroundColor = UIColor.white
    }
    
    override func setupSubViews() {
        view.addSubview(tableView)
        view.addSubview(dailyButton)
        view.addSubview(totalButton)
        
        tableView.dataSource = self
        tableView.delegate = self
        tableView.register(PKMContributionListControllerCell.self, forCellReuseIdentifier: PKMContributionListControllerCellID)
        
        dailyButton.setTitle("日榜", for: .normal)
        dailyButton.addBlock(for: .touchUpInside) { (_) in
            //TODO:打开日榜
        }
        dailyButton.setTitleColor(UIColor.black, for: .normal)
        dailyButton.setTitleColor(UIColor.darkGray, for: .normal)
        
        totalButton.setTitle("总榜", for: .normal)
        totalButton.addBlock(for: .touchUpInside) { (_) in
            //TODO:打开总榜
        }
        totalButton.setTitleColor(UIColor.black, for: .normal)
        totalButton.setTitleColor(UIColor.darkGray, for: .normal)
    }
    
    override func setupSubViewsConstraints() {
        tableView.snp.makeConstraints { (make) in
            make.top.equalTo(dailyButton.snp.bottom)
            make.left.equalTo(view.snp.left)
            make.right.equalTo(view.snp.right)
            make.bottom.equalTo(view.snp.bottom)
        }
        
        dailyButton.snp.makeConstraints { (make) in
            make.left.equalTo(view.snp.left)
            make.height.equalTo(44)
            make.top.equalTo(view.snp.top).offset(60)
            make.width.equalTo(APP_WIDTH*0.5)
        }
        
        totalButton.snp.makeConstraints { (make) in
            make.right.equalTo(view.snp.right)
            make.height.equalTo(44)
            make.top.equalTo(view.snp.top).offset(60)
            make.width.equalTo(APP_WIDTH*0.5)
        }
    }
    
    override func setupNavigationBar() {
        self.title = "M币贡献榜"
    }
    
    override func bindViewModel() {
        
    }


}

extension PKMContributionListController{
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCell(withIdentifier: PKMContributionListControllerCellID, for: indexPath)
        
        return cell
        
    }
    func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        

    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        
        print("点击了" + String(describing: indexPath))
    }
}
